﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using AMPLibrary.Windows;

namespace MediaLibrary
{
    /// <summary>
    /// Interaction logic for MediaCentrePage.xaml
    /// </summary>
    public partial class MediaCentrePage : Page
    {
        private AMPLibrary.Media.MediaPlayer mediaPlayer;

        public MediaCentrePage()
        {
            InitializeComponent();

            this.Focusable = true;
        }        

        /// <summary>
        /// Method, changes the full screen status of the player
        /// </summary>
        /// <param name="fullScreen"></param>
        public void ChangeFullScreenStatus(bool fullScreen)
        {
            if (fullScreen)
            {
                MainWindow window = (MainWindow)App.Current.Windows[0];
                if (window != null)
                {
                    window.ShowMainMenuControls(false);

                    if (window.pagePlaceHolder != null)
                        window.pagePlaceHolder.Margin = new Thickness(0.0);

                    double windowWidth = FullScreenHelper.GoFullscreen(window);
                }
                
                FocusManager.SetIsFocusScope(this, true);
                Keyboard.Focus(this);
                this.Focus();

                mediaPlayer = AMPLibrary.Media.MediaPlayer.GetMediaPlayer(ref mediaCanvas);
            }
            else
            {
                MainWindow window = (MainWindow)App.Current.Windows[0];
                if (window != null)
                {
                    window.ShowMainMenuControls(true);

                    if (window.pagePlaceHolder != null)
                        window.pagePlaceHolder.Margin = new Thickness(6.0);

                    window.WindowState = WindowState.Normal;
                    window.WindowStyle = WindowStyle.SingleBorderWindow;
                    window.Topmost = false;
                    window.ShowInTaskbar = true;
                    window.ResizeMode = ResizeMode.CanMinimize | ResizeMode.CanResize;

                    window.SetPage(Pages.NowPlaying);
                    NowPlayingPage nowPlayingPage = NowPlayingPage.GetNowPlayingPage();
                    //mediaPlayer = AMPLibrary.Media.MediaPlayer.GetMediaPlayer(ref nowPlayingPage.mediaContentPresenter, ref nowPlayingPage.mediaTimeLineSlider);

                    mediaCanvas.Content = null;
                }
            }
        }

        private void mediaCentrePage_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
                ChangeFullScreenStatus(false); 
        }
    }
}
